package com.shell.arouter.demo.multitype;

import android.widget.TextView;

import androidx.annotation.NonNull;

import com.durian.base.utils.LogUtils;
import com.durian.base.utils.ToastUtils;
import com.durian.ui.adapter.multi.ItemViewBindingProvider;
import com.durian.ui.adapter.multi.ItemViewProvider;
import com.durian.ui.adapter.multi.MultiItemViewBindingHolder;
import com.durian.ui.adapter.multi.MultiItemViewHolder;
import com.durian.ui.adapter.multi.MultiItemViewProvider;
import com.durian.ui.adapter.multi.OnItemClickListener;
import com.henanjianye.soon.communityo2o2.R;
import com.henanjianye.soon.communityo2o2.databinding.ItemMulOneABinding;
import com.henanjianye.soon.communityo2o2.databinding.ItemMulOneMaBinding;

/**
 * 说明：MoreOne
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2019-11-12 16:57
 * <p/>
 * 版本：version 1.0
 */
public class MoreOne extends MultiItemViewProvider<MoreOneBean> {

    public MoreOne(){
        with(new MoreA().setOnItemClickListener(new OnItemClickListener<MoreOneBean>() {
            @Override
            public void onItemClick(int position, MoreOneBean item) {
                ToastUtils.get().shortToast("MoreOne---" + (item.type == 0 ? "A" : "B"));
            }
        })).with(new MoreB().setOnItemClickListener(new OnItemClickListener<MoreOneBean>() {
            @Override
            public void onItemClick(int position, MoreOneBean item) {
                ToastUtils.get().shortToast("MoreOne---" + (item.type == 0 ? "A" : "B"));
            }
        }));
    }

    @Override
    protected Class withLinker(MoreOneBean item) {
        if (item.type == 0){
            return MoreA.class;
        }else if (item.type ==1){
            return MoreB.class;
        }else {
            return null;
        }
    }

    public static class MoreA extends ItemViewBindingProvider<ItemMulOneMaBinding,MoreOneBean> {
        @Override
        protected void convert(MultiItemViewBindingHolder<ItemMulOneMaBinding> holder, @NonNull ItemMulOneMaBinding viewBinding, @NonNull MoreOneBean item, int position) {
            viewBinding.tvNameMa.setText("MoreOneA---" + (item.type == 0 ? "A" : "B"));
        }

//        @Override
//        public void onDestory() {
//            super.onDestory();
//            LogUtils.e("fanly", "MoreOneA destroy()");
//        }
    }
    public static class MoreB extends ItemViewProvider<MoreOneBean> {

        @Override
        protected void convert(@NonNull MultiItemViewHolder holder, @NonNull MoreOneBean item, int position) {
            TextView tv = holder.getView(R.id.tv_name_mb);
            tv.setText("MoreOneB---" + (item.type == 0 ? "A" : "B"));
        }

        @Override
        protected int getItemLayoutId() {
            return R.layout.item_mul_one_mb;
        }

        @Override
        public void onDestroy() {
            super.onDestroy();
            LogUtils.e("fanly", "MoreOneB destroy()");
        }
    }


}
